package com.hakim.wfb.schedule.threadpool;

import com.hkfs.fundamental.config.FundamentalConfigProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class ThreadPoolConfigration {

    /**
     *
     * @return
     */
    @Bean(name="threadPoolTaskExecutor")
    public ThreadPoolTaskExecutor getThreadPoolTaskExecutor(){
        ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
        int queueCapacity = FundamentalConfigProvider.getInt("dataCenter.parseAsyncTaskExecutor.queueCapacity");
        int corePoolSize = FundamentalConfigProvider.getInt("dataCenter.parseAsyncTaskExecutor.corePoolSize");
        int maxPoolSize = FundamentalConfigProvider.getInt("dataCenter.parseAsyncTaskExecutor.maxPoolSize");
        int keepAliveSeconds = FundamentalConfigProvider.getInt("dataCenter.parseAsyncTaskExecutor.keepAliveSeconds");
        //线程池所使用的缓冲队列
        poolTaskExecutor.setQueueCapacity(queueCapacity);
        //线程池维护线程的最少数量
        poolTaskExecutor.setCorePoolSize(corePoolSize);
        //线程池维护线程的最大数量
        poolTaskExecutor.setMaxPoolSize(maxPoolSize);
        //线程池维护线程所允许的空闲时间
        poolTaskExecutor.setKeepAliveSeconds(keepAliveSeconds);
        poolTaskExecutor.initialize();
        return poolTaskExecutor;
    }
}
